package dao;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import com.mysql.jdbc.Connection;

/**
 * Servlet implementation class ConnectionManager
 */
public class ConnectionManager {

	static Connection connection;
	static String url;

	public static Connection getConnection() {
		try {
			String url = "jdbc:mysql://localhost:3306/diarydb?useEncoding=true&amp;characterEncoding=UTF-8";
			Class.forName("com.mysql.jdbc.Driver");

			try {
				connection = (Connection) DriverManager.getConnection(url, "root", "root1234");

				// initial query to allow inserting
				String query = "set names utf8";
				Statement statement = connection.createStatement();
				statement.execute(query);

			} catch (SQLException ex) {
				ex.printStackTrace();
			}
		} catch (ClassNotFoundException e) {
			System.out.println(e);
		}
		return connection;
	}
}
